<template>
  <div class="goodsinfo-container">
    <div class="mui-card">
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <!-- 轮播图展示 -->
          <swiper :bannerList="bannerList" :isfull="false"></swiper>
        </div>
      </div>
    </div>
    <div class="mui-card">
      <div class="mui-card-header">{{goodsInfo.title}}</div>
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <p class="price">
            市场价:
            <del>&yen;{{goodsInfo.sell_price}}</del>&nbsp;&nbsp;销售价:
            <span class="now_price">&yen;{{goodsInfo.market_price}}</span>
          </p>
          <p>购买数量:
            <numberbox @changenumber="goCount" :max="goodsInfo.stock_quantity"></numberbox>
          </p>
          <p>
            <mt-button type="primary" size="small">立即购买</mt-button>
            <mt-button type="danger" size="small" @click="addToCar">加入购物车</mt-button>
          </p>
        </div>
      </div>
    </div>
    <div class="mui-card">
      <div class="mui-card-header">商品参数</div>
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <p>商品货号:{{goodsInfo.id}}</p>
          <p>库存情况:{{goodsInfo.stock_quantity}}</p>
          <p>上架时间:{{goodsInfo.id}}</p>
        </div>
      </div>
      <div class="mui-card-footer">
        <mt-button type="primary" size="large" plain @click="goDesc(goodsId)">图文介绍</mt-button>
        <mt-button type="danger" size="large" plain @click="goComment(goodsId)">商品评论</mt-button>
      </div>
    </div>
  </div>
</template>

<script>
import { Toast } from "mint-ui";
import swiper from "../subcomponent/swiper.vue";
import numberbox from "../subcomponent/NumberBox.vue";
export default {
  data() {
    return {
      goodsId: this.$route.params.id,
      bannerList: [],
      goodsInfo: {},
      selectedCount:1
    };
  },
  created() {
    this.getBannerList();
    this.getGoodsInfo();
  },
  methods: {
    getBannerList() {
      this.$http.get("banner/goodslist").then(result => {
        if (result.body.status === 0) {
          console.log(result.body.message);
          result.body.message.forEach(item => {
            item.img = item.src;
          });
          this.bannerList = result.body.message;
          // Toast({
          //   message: "轮播图加载成功",
          //   position: "bottom",
          //   duration: 3000
          // });
        }
      });
    },
    getGoodsInfo() {
      this.$http.get("goods/info/" + this.goodsId).then(result => {
        if (result.body.status === 0) {
          this.goodsInfo = result.body.message;
          console.log(this.goodsInfo);
          Toast({
            message: "商品数据加载成功",
            position: "bottom",
            duration: 3000
          });
        }
      });
    },
    goDesc(id) {
      this.$router.push("/home/goodsdesc/" + id);
    },
    goComment(id) {
      this.$router.push("/home/goodscomment/" + id);
    },
    goCount(data){
      this.selectedCount = data
    },
    addToCar(){
      let car  = {id:this.goodsId,count:this.selectedCount,price:this.goodsInfo.sell_price,selected:true}
      this.$store.commit('addToCar',car)
    }
  },
  components: {
    swiper,
    numberbox
  }
};
</script>

<style lang="scss" scoped>
.goodsinfo-container {
  background-color: #eee;
  overflow: hidden;

  .now_price {
    color: #f00;
    font-size: 16px;
  }
}
.mui-card-footer {
  display: block;
  button {
    margin: 10px 0;
  }
}
</style>
